package com.chaosj.webmagic.handler.domain;

import com.chaosj.webmagic.handler.AbstractWriterHandler;
import com.chaosj.webmagic.handler.IWriterHandler;
import com.chaosj.webmagic.handler.IXPathConfig;
import com.google.common.base.Splitter;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;

import java.util.List;

/**
 * @className: SentinelguardWriterHandler
 * @description:
 * @author: caoyangjie
 * @date: 2022/3/10
 **/
public class SentinelGuardWriterHandler extends AbstractWriterHandler implements IWriterHandler {

    @Override
    public IXPathConfig config() {
        return new IXPathConfig() {
            @Override
            public String titleXPath() {
                return null;
            }

            @Override
            public String contentXPath() {
                return "//section";
            }

            @Override
            public String authorXPath() {
                return null;
            }
        };
    }

    @Override
    public Site getSite() {
        return Site.me().setDomain("https://sentinelguard.io");
    }

    @Override
    protected String defaultAuthor(Page page) {
        return "sentinel";
    }

    @Override
    protected String defaultTitle(Page page) {
        List<String> titles = Splitter.on("/").splitToList(page.getUrl().get());
        String end = titles.get(titles.size()-1);
        return end.substring(0, end.length()-5);
    }
}
